#!/bin/sh

INSTALL_PATH="$HOME/.lovenote"

# check if the $INSTALL_PATH directory exist
if [ -d $INSTALL_PATH ]; then
	#do nothing
	echo "directory $INSTALL_PATH already exist"
else
	mkdir $INSTALL_PATH
	echo "directory $INSTALL_PATH created"
fi

# copy the whole img and src directories in the INSTALL_PATH
echo "copying the img and the src directories in the INSTALL_PATH"
cp -r ./img ./src $INSTALL_PATH


CONFIG_TXT="GLADE_FILE = \"$INSTALL_PATH/src/glade/note.glade\"\n\
\
POSTIT_IMG = \"$INSTALL_PATH/img/postit_green.xpm\"\n\
\
CLOSE_IMG = \"$INSTALL_PATH/img/close.png\"\n\
\
HIDE_CLOSE_IMG = \"$INSTALL_PATH/img/close_hide.png\"\n\
\
DB_NAME = \"$INSTALL_PATH/src/data/notes.db\""

# create $INSTALL_PATH/src/love/config.txt file
echo "create the config.txt file"
sh -c "echo '$CONFIG_TXT' > $INSTALL_PATH/config.txt"


# copy the icon
echo "copy the icon in /usr/share/pixmaps/"
sudo cp ./img/lovenote.png /usr/share/pixmaps/

# create the bonobo servers file in /usr/lib/bonobo/servers

BONOBO_SERVERS="<oaf_info>\n\
\n\
	<oaf_server iid=\"OAFIID:Gnome_Panel_LoveNote_Factory\" type=\"exe\" location=\"$HOME/.lovenote/src/love/lovenote.py\">\n\
		<oaf_attribute name=\"repo_ids\" type=\"stringv\">\n\
			<item value=\"IDL:Bonobo/GenericFactory:1.0\"/>\n\
			<item value=\"IDL:Bonobo/Unknown:1.0\"/>\n\
		</oaf_attribute>\n\
		<oaf_attribute name=\"name\" type=\"string\" value=\"Love Note Applet\"/>\n\
		<oaf_attribute name=\"description\" type=\"string\" value=\"Love Note Applet\"/>\n\
	</oaf_server>\n\
\n\
	<oaf_server iid=\"OAFIID:Gnome_Panel_LoveNote\" type=\"factory\" location=\"OAFIID:Gnome_Panel_LoveNote_Factory\">\n\
		<oaf_attribute name=\"repo_ids\" type=\"stringv\">\n\
			<item value=\"IDL:GNOME/Vertigo/PanelAppletShell:1.0\"/>\n\
			<item value=\"IDL:Bonobo/Control:1.0\"/>\n\
			<item value=\"IDL:Bonobo/Unknown:1.0\"/>\n\
		</oaf_attribute>\n\
		<oaf_attribute name=\"name\" type=\"string\" value=\"LoveNote\"/>\n\
		<oaf_attribute name=\"description\" type=\"string\" value=\"Love Note Applet\"/>\n\
		<oaf_attribute name=\"panel:category\" type=\"string\" value=\"Utility\"/>\n\
		<oaf_attribute name=\"panel:icon\" type=\"string\" value=\"lovenote.png\"/>\n\
	</oaf_server>\n\
\n\
</oaf_info>"

echo "create the bonobo servers file, lovenote.servers, in /usr/lib/bonobo/servers/"
sudo su -c "echo -e '$BONOBO_SERVERS' > /usr/lib/bonobo/servers/lovenote.server"


echo "Installation finished"
echo "\nNow you can add the loveNote applet to your gnome panel:\n\
1) right click on you gnome panel\n\
2) click the 'add to panel' button'\n\
3) search for the loveNote applet\n\
4) select the loveNote applet and click add\n\
\nThat's all! ;)"

exit 0
